﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <link href="../CSS/Style1.css" rel="stylesheet" type="text/css" />
    <link href="../CSS/style4.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.pager.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.showModalDialog.js" type="text/javascript"></script>
    <script type="text/javascript">
        //将“/Date(1420646400000)/”转为“2015-01-08”
        function date2str(date) {
            //null判断
            if (date == null) return "";
            //去掉左右的斜杠
            date = date.replace(/\//g, "");
            //将其转为一个日期对象
            eval("var d = new " + date + ";");
            //返回最终结果
            return d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate()+"日";
        }
        function Load() {
            $("#dataDiv .dataTable tr:gt(0)").live("click", function () {
                $("#dataDiv .dataTable tr:gt(0)").css("background-color", "white");
                $(this).css("background-color", "pink");
                $("#dataDiv div:first").css("background-image", "url(../images/bg.gif)");
                $("#dataDiv div:last").css("background-image", "url()");
            });
        }
        //进行分页
        $(function () {
            Load();
            reloadList();
        })

        //刷新
        function reloadList() {
            //注册分页器控件
            $("#pageDiv").empty().pager("SaleAllot.ashx", { action: "paging" }, function (data) {
                //展示查询的结果
                $("#tb1 tr:gt(0)").remove();
                var tb1 = $("#tb1").get(0);
                for (var i = 0; i < data.length; i++) {
                    var tr = tb1.insertRow(-1);
                    tr.insertCell(-1).innerHTML = data[i].ChanName || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanTitle || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanLinkMan || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanLinkTel || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanCreateName || "";
                    tr.insertCell(-1).innerHTML = date2str(data[i].ChanCreateDate) || "";
                    if (data[i].ChanDueMan==null) {
                        tr.insertCell(-1).innerHTML = '<input type="text" style="text-align:center;width:87px" value="双击选择" readonly="readonly" ondblclick="showEmp(' + data[i].ChanID + ')" />';
                    }else{
                        tr.insertCell(-1).innerHTML = '<input type="text" style="text-align:center;width:87px" value="' + data[i].ChanDueName + '" readonly="readonly" ondblclick="showEmp(' + data[i].ChanID + ')" />';
                    }
                    
                }
            });

        }

        function Cha() {
            var sta = {
                action: "select",
                ChanName: $("#txtChanName").val(),
                ChanLinkMan: $("#txtChanLinkMan").val(),
                ChanCreateMan: $("#txtChanCreateMan").val(),
                ChanDueMan: $("#txtChanDueMan").val()
            };

            //注册分页器控件
            $("#pageDiv").empty().pager("SaleAllot.ashx", sta, function (data) {
                //展示查询的结果
                $("#tb1 tr:gt(0)").remove();
                var tb1 = $("#tb1").get(0);
                for (var i = 0; i < data.length; i++) {
                    var tr = tb1.insertRow(-1);
                    tr.insertCell(-1).innerHTML = data[i].ChanName || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanTitle || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanLinkMan || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanLinkTel || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanCreateName || "";
                    tr.insertCell(-1).innerHTML = date2str(data[i].ChanCreateDate) || "";
                    tr.insertCell(-1).innerHTML = '<input type="text" value="' + data[i].ChanDueName + '" readonly="readonly" ondblclick="showEmp(' + data[i].ChanID + ')" />';
                }
            });

        }

        //修改指派人
        function showEmp(ChanID) {
            $.showModalDialog("../publicPage/SelectEmp.htm?data=" + Math.random(), null, 200, 220, function (UserID) {
                if (UserID) {
                    var ch = {
                        action: "ChanDueMan",
                        ChanID: parseInt(ChanID),
                        UserID: parseInt(UserID)
                    };
                    $.post("SaleAllot.ashx", ch, function (r) {
                        if (r == "1") {
                            reloadList();
                        } else {
                            alert("指派人修改成功");
                        }
                    });
                }

            });

        }
        
    </script>
</head>
<body>
<div id="desDiv">
    <span>销售机会分配</span><br />
    销售主管查看销售机会，并将销售机会分配给合适的销售人员
</div>
<table class="tableEdit">
    <tr>
        <th>客户名称：</th>
        <td><input type="text" id="txtChanName" style="color:blue;width:130px" /></td>
        <th>联系人：</th>
        <td><input type="text"  id="txtChanLinkMan" style="color:blue;width:130px" /></td>
         <th>创建人：</th>
        <td><input type="text"  id="txtChanCreateMan" style="color:blue;width:130px" /></td>
        <th>指派人：</th>
        <td><input type="text"  id="txtChanDueMan" style="color:blue;width:130px" /></td>
    </tr>
    <tfoot>
        <tr>
            <td colspan="8"><input type="button" value="查询" onclick="Cha();" /></td>
        </tr>
    </tfoot>
</table>
<br />
<div id="dataDiv">
    <table class="dataTable" id="tb1">
        <tr style="text-align:center;">
            <th align="center">客户名称</th>
            <th align="center">概要</th>
            <th align="center">联系人</th>
            <th align="center">联系电话</th>
            <th align="center">创建人</th>
            <th align="center">创建时间</th>
            <th align="center">分配人</th>
        </tr>
    </table>
     <div id="pageDiv">
    </div>
</div>
</body>
</html>
